var LOCALHOSTURL = "http://localhost:8080";

function myAjax(url, type, data) {
    console.log(data);
    let user = $.cookie("token");
    let result = null;
    $.ajax({
        url: LOCALHOSTURL + url,
        type: type,
        async: false,//必须写该句，才能同步处理
        headers: {
            "Authorization": $.cookie("token")
        },
        data: data,
        dataType: "json",
        // contentType: "application/json",
        xhrFields: {
            withCredentials: true //默认情况下，标准的跨域请求是不会发送cookie的
        },
        success: function (data) {
            result = data;
            console.log(result);
            if (result.code==403)
                layer.alert(result.message,{icon:2});
        },
        error: function (data) {
            result = {code: 500, message: "内部服务器遇到错误"};
            console.log(data);
        }
    });
    return result;
}

function ajaxModel(url, type, data) {
    console.log(data);
    let result = null;
    $.ajax({
        url: LOCALHOSTURL + url,
        type: type,
        async: false,//必须写该句，才能同步处理
        headers: {'Authorization': $.cookie("token")},
        data: JSON.stringify(data),
        dataType: "json",
        contentType: "application/json",
        xhrFields: {
            withCredentials: true //默认情况下，标准的跨域请求是不会发送cookie的
        },
        success: function (data) {
            result = data;
            console.log(result);
        },
        error: function (data) {
            result = {code: 500, message: "内部服务器遇到错误"};
            console.log(data);
        }
    });
    return result;
}